/*
 * *
 *  * Copyright (c) iwindplus Technologies Co., Ltd.2024-2030, All rights reserved.
 *
 *
 */

package com.iwindplus.boot.operate;

import com.iwindplus.boot.operate.aspect.OperateLogAspect;
import com.iwindplus.boot.operate.domain.property.OperateLogProperty;
import com.iwindplus.boot.operate.listener.OperateLogListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 日志配置.
 *
 * @author zengdegui
 * @since 2020/11/8
 */
@Slf4j
@Configuration
@ConditionalOnProperty(prefix = "operate.log", name = "enabled", havingValue = "true", matchIfMissing = true)
@EnableConfigurationProperties(OperateLogProperty.class)
public class OperateLogConfiguration {

    /**
     * 创建 OperateLogAspect.
     *
     * @return OperateLogAspect
     */
    @Bean
    public OperateLogAspect operateLogAspect() {
        OperateLogAspect operateLogAspect = new OperateLogAspect();
        log.info("OperateLogAspect={}", operateLogAspect);
        return operateLogAspect;
    }

    /**
     * 创建 OperateLogListener.
     *
     * @return OperateLogListener
     */
    @Bean
    public OperateLogListener operateLogListener() {
        OperateLogListener operateLogListener = new OperateLogListener();
        log.info("OperateLogListener={}", operateLogListener);
        return operateLogListener;
    }
}
